package com.example.demo.controller;

import com.example.demo.entity.Book;
import com.example.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("{id}")
    public Book getById(@PathVariable String id){
        return bookService.getCacheById(id);
    }



    @RequestMapping("/test")
    @ResponseBody
    @Cacheable(value = "cacheSpace",key="test")
    public String test(){
        System.out.println("没有调用缓存");
        return "linjiaan";
    }
}
